package com.show.dao.sys_menu;

import com.show.dto.sys_menu.SysMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 顾志杰 on 2018/1/31.
 */
@Repository
public interface MenuRepositoty extends JpaRepository<SysMenu, Integer>, JpaSpecificationExecutor<SysMenu> {
    @Modifying
    @Query(value = "update sys_menu set sts='1' where grid_id=?",nativeQuery = true)
    String update(String grid_id);

    @Query(value = "select * from sys_menu where sts='1'",nativeQuery = true)
    List<SysMenu> findAllMenu();

    @Query(value = "SELECT\n" +
            "	DISTINCT mm.*\n" +
            "FROM\n" +
            "	sys_emp e\n" +
            "LEFT JOIN sys_emp_role rr ON e.emp_id = rr.emp_id\n" +
            "LEFT JOIN sys_role r ON rr.role_id = r.role_id\n" +
            "LEFT JOIN sys_role_menu rm ON rm.role_id = r.role_id\n" +
            "LEFT JOIN sys_menu mm ON mm.menu_id = rm.menu_id \n" +
            "WHERE\n" +
            "	e.login_name = ? AND mm.level = 1 order by mm.menu_id",nativeQuery = true)
    List<SysMenu> getMenus(String name);


}
